package com.raja.servingStation.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.raja.servingStation.common.constant.Constants;
import com.raja.servingStation.common.constant.MysqlPageVo;
import com.raja.servingStation.dao.NoticeDao;
import com.raja.servingStation.dao.NoticeViewDao;
import com.raja.servingStation.entity.Notice;
import com.raja.servingStation.entity.vo.NoticeDetail;
import com.raja.servingStation.entity.vo.NoticeReadingDetail;
import com.raja.servingStation.entity.vo.NoticeState;
import com.raja.servingStation.entity.vo.NoticeView;
import com.raja.servingStation.service.NoticeService;
import com.raja.servingStation.service.NoticeViewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 公文服务实现
 * 2017/9/30
 */
@Service
public class NoticeViewServiceImpl implements NoticeViewService {

    @Autowired
    NoticeViewDao noticeViewDao;

    @Override
    public MysqlPageVo queryNoticeSubscribeListByPage(JSONObject body) throws Exception {
        Integer pageSize = body.getInteger("pageSize");
        Integer currPage = body.getInteger("currPage");
        MysqlPageVo mysqlPageVo = new MysqlPageVo();
        if (pageSize == null)
            pageSize = Constants.pageSize;
        mysqlPageVo.setPageSize(pageSize, currPage);
        int count = noticeViewDao.cntNoticeSubscribeList(body).intValue();
        mysqlPageVo.setTotal(count);
        if (count > 0) {
            List<NoticeView> noticeViews = noticeViewDao.queryNoticeSubscribeListByPage(body, mysqlPageVo);

            mysqlPageVo.setData(noticeViews);
        }
        return mysqlPageVo;
    }


    /**
     * 公文详情
     * @param body
     * @return
     * @throws Exception
     */
    @Override
    public NoticeDetail queryNoticeDetail(JSONObject body) throws Exception {
        Long noticeId = body.getLong("noticeId");
        NoticeDetail noticeDetail = noticeViewDao.queryNoticeDetail(noticeId);
        // 绑定附件
        noticeDetail.setNoticeAttachs(noticeViewDao.queryNoticeAttachs(noticeId));

        return noticeDetail;
    }



}
